<template>
	<view class="box">
		<view class="goods">
			<!-- @click="goDetails(item.id)" -->
			<view class="goods_box flex_Z" v-for="(item,index) in googsList" :key="index">
				<image :src="item.thumb" mode="aspectFill"></image>
				<view class="goods_btm">
					<text class="f28 c3 overflow2">{{item.name}}</text>
					<view class="goods_btm_price flex_ld">
						<view class=" flex_dq">
							<text class="f24 c4">￥</text>
							<text class="f28 c4 fw7 price">{{item.price}}</text>
						</view>
						<text class="f26 c9 send" @click="sendgoods(item)">发送</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 暂无数据 / 加载更多 -->
		<noDatas :xxxList="googsList" :status="status"></noDatas>
	</view>
</template>

<script>
	import {
		customerGood,
		pushHxMessage
	} from "@/api/shoppingCart.js"
	import {
		shopDetail
	} from "../../api/settled.js"
	export default {
		data() {
			return {
				baseUrl: this.$imageBaseUrl,
				page: 1,
				size: 10,
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				googsList: [],
				seller_id: "",
				astoreUserId:"",
			}
		},
		onLoad(e) {
			if (e.id) {
				this.seller_id = e.id
			}
			this.getshopDetail()
			this.getList()
		},
		methods: {
			getshopDetail(){
				const data = {
					seller_id: this.seller_id
				}
				shopDetail(data).then(res => {
					console.log(res);
					if (res.code == 1) {
						this.astoreUserId = res.data.user_id
					}
				
				})
			},
			getList() {
				let data = {
					seller_id: this.seller_id,
					page_no: this.page,
					page_size: this.size,
					mask: 1
				}
				customerGood(data).then(res => {
					let list = res.data.list;
					this.googsList = this.page == 1 ? list : this.googsList.concat(list);
					console.log(this.googsList);
					if (list.length < this.size) this.status = 'nomore';
					else this.status = 'loading';
				})
			},
			sendgoods(item){
				let data = {
					to_user:this.astoreUserId,
					data_id:item.id,
					type:1
				}
				pushHxMessage(data).then(res=>{
					console.log(res);
					if(res.data.is_push_success == true){
						uni.$u.toast('发送成功')
						setTimeout(()=>{
							uni.navigateBack()
						},500)
					}
				})
			},
			// 去详情
			goDetails(id) {
				uni.navigateTo({
					url: '/pagesMy/cloudCat/goodsDetails?id=' + id
				})
			}

		},
		onUnload() {
			console.log('触发卸载');
			uni.removeStorageSync("nextFloor")
		},
		// 下拉刷新
		onPullDownRefresh() {
			let that = this;
			setTimeout(function() {
				that.page = 1
				this.getList()
			}, 800);
		},
		//触底加载
		onReachBottom() {
			if (this.status != 'nomore') {
				this.page = this.page + 1
				this.getList()
			}
		}
	}
</script>

<style scoped lang="scss">
	.goods {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		align-items: center;
		width: 690rpx;
		margin: 0rpx auto;

	}

	.goods_box {
		width: 330rpx;
		height: 440rpx;
		border-radius: 12rpxx;
		background: #ffffff;
		margin-top: 30rpx;
		padding: 18rpx 18rpx 28rpx;
	}

	.goods_box>image {
		width: 294rpx;
		height: 294rpx;
		border-radius: 4rpx;
	}



	.goods_btm {
		width: 100%;
	}

	.overflow2 {
		width: 100%;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		margin-top: 18rpx;
	}

	.integral {
		padding: 4rpx 14rpx;
		border-radius: 10rpx;
	}

	.goods_btm_price {
		margin-top: 20rpx;
	}

	.price {
		margin-right: 6rpx;
	}
	.send{
		width: 92rpx;
		height: 44rpx;
		background: linear-gradient( 270deg, #FA2222 2%, #FFC400 98%);
		border-radius: 152rpx 152rpx 152rpx 152rpx;
		color: #ffffff;
		text-align: center;
		line-height: 44rpx;
	}
</style>